* Article title: "Who is Credible? Government Popularity and the Catalytic Effect of IMF Lending"

* Journal: Comparative Political Studies

* Author: Sujeong Shim, University of Zurich

* This replication code is for Figure 4.
* This Stata do-file is for use with the accompanying datset saved as "Main dataset.dta".

*Stata version: 16.1





clear
set more off

use "C:\Users\sujeo\OneDrive\바탕 화면\RESEARCH\DRAFTS\2020 publication version\4차 submission\RnR\Main dataset.dta", replace

/* Prepare the data. */

#Lagging variables by one period: 

sort ccode year

by ccode: gen lag_popularity = popularity[_n-1]
by ccode: gen lag_imf=imf[_n-1]
by ccode: gen lag_IMF_cond=IMF_cond[_n-1]
by ccode: gen lag_logIMFloan=logIMFloan[_n-1]
by ccode: gen lag_default=default[_n-1]
by ccode: gen lag_polity2=polity2[_n-1]
by ccode: gen lag_veto=veto[_n-1]
by ccode: gen lag_budget_bal=budget_bal[_n-1]
by ccode: gen lag_UNvoting=UNvoting[_n-1]
by ccode: gen lag_right_gov=right_gov[_n-1]
by ccode: gen lag_growth=growth[_n-1]
by ccode: gen lag_curr=curr[_n-1]
by ccode: gen lag_logGDPPC=logGDPPC[_n-1]
by ccode: gen lag_participation=participation[_n-1]
by ccode: gen lag_ln_liquidity=ln_liquidity[_n-1]
by ccode: gen lag_QPCSPCavrg=QPCSPC_TOT_avrg[_n-1]
by ccode: gen lag_QPCSPC=QPCSPC_TOT[_n-1]


#Differencing variables


gen spread_dif=spread_avg_an - lag_spread
gen popularity_dif=popularity-lag_popularity
gen imf_dif=imf-lag_imf
gen IMF_cond_dif=IMF_cond-lag_IMF_cond
gen logIMFloan_dif=logIMFloan-lag_logIMFloan
gen election_dif=election-lag_election
gen default_dif=default-lag_default
gen right_gov_dif=right_gov-lag_right_gov
gen growth_dif=growth-lag_growth
gen polity2_dif=polity2-lag_polity2
gen curr_dif=curr-lag_curr 
gen UNvoting_dif=UNvoting-lag_UNvoting
gen participation_dif=participation-lag_participation
gen QPCSPC_dif=QPCSPC_TOT-lag_QPCSPC
gen veto_dif=veto-lag_veto
gen budget_bal_dif=budget_bal-lag_budget_bal



#Key independent variables


gen lag_imf_lag_popularity=lag_imf*lag_popularity
gen lag_imf_popularity_dif=lag_imf*popularity_dif



#Selection bias 


probit imf c.lag_UNvoting##c.lag_ln_liquidity c.lag_participation##c.lag_ln_liquidity lag_curr lag_growth lag_logGDPPC lag_veto lag_right_gov lag_election
predict xb2, xb
predict phat2, pr

gen bias=normalden(xb2)/phat2
by ccode: gen lag_bias=bias[_n-1]


/* Run standard regression. */



xtreg spread_dif lag_imf lag_imf_popularity_dif lag_imf_lag_popularity lag_popularity popularity_dif lag_spread lag_bias lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_polity2 polity2_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_participation, fe




/* Gather parameters, initialize matrix for runs */
quietly summarize lag_popularity, detail 
local min=r(min)
local max=r(max)
local cen10=r(p10)
local cen20=r(p20)
local cen30=r(p30)
local cen40=r(p40)
local cen50=r(p50)
local cen60=r(p60)
local cen70=r(p70)
local cen80=r(p80)
local cen90=r(p90)
local numparams=13  

local inc=(`max'-`min')/(`numparams'-1)
local iter=0
matrix foo2 = 0,0,0,0
local order=1  






/* Calculate coefficients on IMF programs across Government Popularity, store in matrix foo2 */
while `iter'<`numparams' { 
   gen lag_popularitya=lag_popularity-`min'-(`inc'*`iter')  
   summarize lag_popularitya
   gen x1x2a=lag_imf*lag_popularitya

xtreg spread_dif lag_imf x1x2a lag_imf_popularity_dif lag_popularity popularity_dif lag_spread lag_bias lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_polity2 polity2_dif lag_election lag_veto veto_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_participation, fe





matrix betas=e(b)                
   scalar lag_imfcoef=betas[1,`order']
   matrix ses=e(V)
   scalar lag_imfse=sqrt(ses[`order',`order'])
   local obs=e(N)                  
   scalar ci95=invnorm(0.975) 
   local xval = `min'+(`inc'*`iter')
   matrix foo = lag_imfcoef-ci95*lag_imfse, lag_imfcoef, lag_imfcoef+ci95*lag_imfse, `xval'
   matrix foo2 = foo2 \ foo
   drop lag_popularitya x1x2a
   local iter=`iter'+1
   }


   
   
   
  
matrix points=foo2[2..(`numparams'+1),1..4]
svmat points


twoway (connect points1 points2 points3 points4, mcolor(navy maroon navy)/*
*/ clcolor(navy maroon navy) lpattern(dash solid dash) lwidth(medium medthick medium) msize(small small small) msym(i D i))/*
*/(histogram lag_popularity if e(sample), bin(50) yaxis(2) blcolor(gray) bfcolor(none)), ytitle(Histogram of /*
*/Government Popularity, axis(2) size(4))/*
*/ ytitle("Coefficients and 95% CIs", size(4))/*
*/ xlab(1 20 40 60 80 100) ylabel(, labsize(4)) yline(0, lwidth(medthick)) tit("Coefficients on IMF program by Government Popularity") xtitle("Government Popularity (%)", size(4)) xscal(titlegap(2)) yscal(titlegap(2))/*
*/  xsca(titlegap(2)) yscal(titlegap(2))/*
*/  legend(off) scheme(s2mono)

